package Gui;


import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JTextField;
import java.awt.Component;
import javax.swing.*;
import Control.UserLibrarian;
import Control.UserSubscriber;
import java.awt.SystemColor;
import javax.swing.JLabel;
import java.awt.Color;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.event.ActionListener;
import javax.swing.JLayeredPane;
import client.LibaryMain;
import Gui.*;
import Logic.LoginInfo;

import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.Font;
import java.util.ArrayList;

/**
 * this class implements gui Librarian Window
 * @author Ron Shenkerman
 * @author Gabi Revah
 * @author Aviad Almog
 * @author Ivan Onyshchenko
 */
public class LibrarianWindow extends JPanel  {
	
	
	
	private static final long serialVersionUID = 1L;
	private JTextField PasswordTextField;
	private JTextField UserNameTextField;
	private JButton btnAddABook_1;
    public static LendingGui lend;
    public static RemoveBook rb;
	public static AddBook addbook;
	public static UpdateBookDetails ubd;
	public static ReturnBookgui retb;
	public static Viewlending vv;
	
	/**
	 *  creates the Librarian Window
	 */
	public LibrarianWindow() {
		
		setBackground(new Color(153, 204, 255));
		setSize(1000,710);
		
		initComponents();
	
	}
		
	
/**
 * initilizing the Librarian Window
 */
		public void  initComponents() {
			
			JButton btnLogout = new JButton("Logout");
			btnLogout.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 14));
			btnLogout.setBounds(849, 591, 87, 25);
			btnLogout.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					ArrayList<String> Arr=new ArrayList<String>();
					Arr.add("Logout");
					Arr.add("Worker");
					Arr.add(LoginInfo.UserName);
					LibaryMain.chat.handleMessageFromGui(Arr);
					MainScreen.cardLayot.show(MainScreen.card, "Login");
					
				}
			});
			
			JButton btnRigesterSubscriber = new JButton("Rigester New Subscriber");
			btnRigesterSubscriber.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
			btnRigesterSubscriber.setBounds(342, 133, 299, 39);
			btnRigesterSubscriber.addActionListener(new java.awt.event.ActionListener() {     // Login action listener 
	            public void actionPerformed(java.awt.event.ActionEvent evt) {
	            	btnRigesterSubscriberActionPerformed(evt);
	            
	            
					
				}
	        });
			
			
			
			JButton btnLending = new JButton("Lending");
			btnLending.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
			btnLending.setBounds(342, 237, 299, 39);
			
			btnLending.addActionListener(new java.awt.event.ActionListener() {     // View Subscriber Details action listener 
	            public void actionPerformed(java.awt.event.ActionEvent ev) {
	            	btnLending(ev);
	            					
				}
	        });
			JButton btnViewSubscriberDetails = new JButton("View Subscriber Details");
			btnViewSubscriberDetails.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
			btnViewSubscriberDetails.setBounds(342, 289, 299, 39);
			
			btnViewSubscriberDetails.addActionListener(new java.awt.event.ActionListener() {     // View Subscriber Details action listener 
	            public void actionPerformed(java.awt.event.ActionEvent ev) {
	            	btnViewSubscriberDetails(ev);
	            					
				}
	        });
			
			JButton btnAddABook = new JButton("Add a Book");
			
			 btnAddABook_1 = new JButton("Add A Book");
			 btnAddABook_1.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
			 btnAddABook_1.setBounds(342, 341, 299, 39);
            btnAddABook_1.addActionListener(new java.awt.event.ActionListener() {     // add book  action listener 
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            btnAddABookActionPerformed(evt);
        
        
                            
                    }
    });
			
			JButton btnRemoveABook = new JButton("Remove A Book");
			btnRemoveABook.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
			btnRemoveABook.setBounds(342, 393, 299, 39);
			btnRemoveABook.addActionListener(new java.awt.event.ActionListener() {     // remove book action listener 
	            public void actionPerformed(java.awt.event.ActionEvent ev) {
	            	btnRemoveABook(ev);
	            					
				}
	        });
			
			
			JButton btnUpdateBookDetails = new JButton("Update Book Details");
			btnUpdateBookDetails.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
			btnUpdateBookDetails.setBounds(342, 445, 299, 39);
			btnUpdateBookDetails.addActionListener(new java.awt.event.ActionListener() {     // remove book action listener 
	            public void actionPerformed(java.awt.event.ActionEvent ev) {
	            	btnUpdateBookDetails(ev);
	            					
				}
	        });
			
			JButton ReturnABook = new JButton("Return A Book");
			ReturnABook.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
			ReturnABook.setBounds(342, 185, 299, 39);
			ReturnABook.addActionListener(new java.awt.event.ActionListener() {     // remove book action listener 
	            public void actionPerformed(java.awt.event.ActionEvent ev) {
	            	ReturnABookaction(ev);
	            					
				}
	        });
			setLayout(null);
			add(ReturnABook);
			add(btnUpdateBookDetails);
			add(btnRemoveABook);
			add(btnRigesterSubscriber);
			add(btnLending);
			add(btnAddABook_1);
			add(btnViewSubscriberDetails);
			add(btnLogout);
			
			JLabel lblWelcomeSubscriber = new JLabel("Welcome Librarian");
			lblWelcomeSubscriber.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 26));
			lblWelcomeSubscriber.setBounds(40, 37, 253, 25);
			add(lblWelcomeSubscriber);
			
			JButton SearchBookbtn = new JButton("Search Book");
			SearchBookbtn.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
			SearchBookbtn.addActionListener(new java.awt.event.ActionListener() {     // remove book action listener 
	            public void actionPerformed(java.awt.event.ActionEvent ev) {
	            	SearchBookbtn(ev);
	            					
				}
	        });
			SearchBookbtn.setBounds(342, 75, 299, 44);
			add(SearchBookbtn);
			
			JLabel label = new JLabel("");
			label.setIcon(new ImageIcon(LibrarianWindow.class.getResource("/Gui/images/user-library.png")));
			label.setBounds(352, 11, 821, 678);
			add(label);
	
			
		
	}
		
	
		protected void ReturnABookaction(ActionEvent ev) {
			DirectorWindow.roll= "LibrarianWindow";
			this.retb = new ReturnBookgui();
			MainScreen.card.add("returnbook", retb);
			MainScreen.cardLayot.show(MainScreen.card, "returnbook");
			
		}



		protected void btnLending(ActionEvent ev) {
			DirectorWindow.roll= "LibrarianWindow";
			this.lend = new LendingGui();
			MainScreen.card.add("lendBook", lend);
			MainScreen.cardLayot.show(MainScreen.card, "lendBook");
			
		}
		
			
			
		
		
		protected void btnUpdateBookDetails(ActionEvent ev) {
		
	            DirectorWindow.roll= "LibrarianWindow";
	            LibrarianWindow.ubd =  new UpdateBookDetails();
            	MainScreen.card.add("UpdateBook", LibrarianWindow.ubd);
	        	MainScreen.cardLayot.show(MainScreen.card, "UpdateBook");
	            }
	      
		    

		protected void btnRemoveABook(ActionEvent ev) {
			DirectorWindow.roll= "LibrarianWindow";
			this.rb = new RemoveBook();
			MainScreen.card.add("removebook", rb);
			MainScreen.cardLayot.show(MainScreen.card, "removebook");
			
		}



		protected void btnAddABookActionPerformed(ActionEvent evt) {
            // TODO Auto-generated method stub
			 DirectorWindow.roll="LibrarianWindow";
			ArrayList<String> Arr=new ArrayList<String>();
	        Arr.add("GetCategory");
		    LibaryMain.chat.handleMessageFromGui(Arr);
		   
		}
		
		
		protected void btnRigesterSubscriberActionPerformed(ActionEvent evt) {
			// TODO Auto-generated method stub
			Rigester reglib = new Rigester("LibrarianWindow");
			MainScreen.card.add("Rigester", reglib);
			MainScreen.cardLayot.show(MainScreen.card, "Rigester");
			
		}
		//this is for open a subscriber view detail window 
		public void btnViewSubscriberDetails(ActionEvent e) {
			DirectorWindow.roll="LibrarianWindow";
			Viewsubscriberdetail view = new Viewsubscriberdetail();
			MainScreen.card.add("viewdetail", view);
			MainScreen.cardLayot.show(MainScreen.card, "viewdetail");
			
		}
		// this is for searching a book
		public void SearchBookbtn(ActionEvent e) {
			DirectorWindow.roll="LibrarianWindow";
			Search sr= new Search();
			MainScreen.card.add("Search",sr);
			MainScreen.cardLayot.show(MainScreen.card, "Search");
			
		}
}
